package com.android.ouderenvervoer;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.os.AsyncTask;
import android.util.Log;
/**
 * Objects of this class send data back and forth from a webserver.
 * The Connector will send a request to a webservice, 
 * and receive a response from that webservice.
 * @author Tim van der Helm
 *
 */
public class SoapConnector // extends AsyncTask <Params, Progress, Result>
{
	private static final String NAMESPACE = "http://vervoer.timvanderhelm.nl/Inventory";
	private static final String URL = "http://vervoer.timvanderhelm.nl/server.php";
	private static final String SOAP_ACTION = "inventory";
	SoapObject request;
	
	public SoapConnector(String methodname)
	{
		request = new SoapObject(NAMESPACE, methodname);
	}
	public void addRequestProperty(String id, Object value)
	{
		request.addProperty(id, value);
	}
	protected String doInBackground(){
	
			String result = "";
			
			try
	        {
				 Log.d("output", "a" ); 
				SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
				 Log.d("output", "0" ); 
		    	envelope.setOutputSoapObject(request);
		    	 Log.d("output", "b" );
		    	HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
		    	 Log.d("output", "c" );
		    	androidHttpTransport.call(SOAP_ACTION, envelope);
		    	 Log.d("output", "d" );
		    	result = (String)envelope.getResponse();
		    	 Log.d("output", "e" );
		    	 Log.d("output", "b0" ); 
	        }
			catch (IOException ex) 
	        {
	        	Logger.getLogger(SoapConnector.class.getName()).log(Level.SEVERE, null, ex);
	        	
	        } 
	        catch (XmlPullParserException ex) 
	        {
	        	Logger.getLogger(SoapConnector.class.getName()).log(Level.SEVERE, null, ex);
	        }
	        catch(Exception ex)
	        {
	        	Logger.getLogger(SoapConnector.class.getName()).log(Level.SEVERE, null, ex);
	        }
	        
	        return result;
	        
		}
	
	protected void onPostExecute(String result){

	}
	
	
	}
	
	
	
	

